#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int arr[10010] = { 0 };
		//bool flag[10010] = { 0 };
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
			//flag[i] = 1;
		}
		int t = n / 2;
		int sum = 0;
		sort(arr, arr + n);
		for (int i = 0; i < n; i++) {
			sum += abs(arr[t] - arr[i]);
		}
		cout << sum << endl;
	}
	return 0;
} 